#coding:utf-8
from email.mime.text import MIMEText
from smtplib import SMTP as smtp
import datetime

class Gmail(object):
    def __init__(self, account, password):
        self.account = "%s@gmail.com"%account
        self.password = password

    def send(self, to, title, content):
        server = smtp('smtp.gmail.com')
        server.docmd("EHLO server")
        server.starttls()
        server.login(self.account, self.password)

        msg = MIMEText(content)
        msg['Content-Type'] = "text/plain; charset='utf-8'"
        msg['Subject'] = title
        msg['From'] = self.account
        msg['To'] = to
        server.sendmail(self.account, to, msg.as_string())
        server.close()

if __name__ == '__main__':
    ohlifepost = 'post+4d353bbd8c9cf@ohlife.com'
    gmail = Gmail("wwq0327", "xxx")
    while True:
        logs = raw_input('日记内容（输入q退出）：')
        if logs.lower() != 'q':
            gmail.send(ohlifepost, "",logs+"//"+str(datetime.datetime.now()))
            print "Done!"
        else:
            print '程序已退出！'
            break

